package com.mayuhao.classmanage.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mayuhao.classmanage.entity.CssClass;
import com.mayuhao.classmanage.entity.CssClassVO;
import com.mayuhao.classmanage.service.ICssClassService;
import com.mayuhao.classmanage.util.Result;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 马宇豪
 * @since 2022-10-25
 */
@RestController
//@RequestMapping("/css-class")
public class CssClassController {

    @Resource
    private ICssClassService classService;

    /**
     * @return com.baomidou.mybatisplus.extension.plugins.pagination.Page<com.mayuhao.classmanage.entity.CssClassVO>
     * @description 请修改方法描述
     * @methodName findPage
     * @params [pageNum, pageSize, searchId, searchName]
     * @paramType [java.lang.Integer, java.lang.Integer, java.lang.String, java.lang.String]
     * @author 马宇豪
     * @date 2022/10/25 0025 下午 5:33
     * @email 1757442521@qq.com
     **/
    @GetMapping("/findpage")

    public Page<CssClassVO> findPage(@RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "7") Integer pageSize, @RequestParam(defaultValue = "") String searchId, @RequestParam(defaultValue = "") String searchName) {
        return classService.findPage(pageNum, pageSize, searchId, searchName);
    }

    @PostMapping("/save")
    public Result imp(@RequestBody CssClass cssClass) {
        return new Result(true, "ok", classService.save(cssClass));
    }

    @PutMapping("/update")
    public Result update(@RequestBody CssClass cssClass) {
        return new Result(true, "ok", classService.updateById(cssClass));
    }

    @DeleteMapping("/delbatch/{ids}")
    public boolean deleteClass(@PathVariable List ids) {
        return classService.removeBatchByIds(ids);
    }

    @DeleteMapping("/delsingle/{id}")
    public boolean deleteClass(@PathVariable Integer id) {
        return classService.removeById(id);
    }


    @GetMapping("/export")
    public void export(HttpServletResponse response) throws IOException {

        classService.export(response);
    }

    @PostMapping("/import")
    public void imp(MultipartFile file) throws Exception {
        classService.imp(file);
    }

    @GetMapping("/findpro")
    public String findPro() {
        return classService.findPro();

    }


}
